<template>
	<view class="pages-view">
		<view class="header-view">发现</view>
		<view style="padding: 30rpx;">
			<view style="margin-bottom: 30rpx;">
				<u-swiper :list="adImage" height="260rpx"></u-swiper>
			</view>
			<view style="margin-bottom: 30rpx;">
				<u-notice-bar :text="rowBar" direction="column" bgColor="#ffffff" color="#000000"
				@click="handleRowBarInfo"></u-notice-bar>
			</view>
			<view class="list-view">
				<view class="list-item" v-for="(item,index) in list" :key="index"
				@click="handleJump(item)">
					<image class="list-item-image" :src="item.image" mode=""></image>
					<view style="padding: 20rpx;">
						<view class="list-item-title">{{item.title}}</view>
						<view class="list-item-bottom">
							<image class="list-icon" src="@/static/images/12.png" mode=""></image>
							<view class="list-item-desc">{{item.synopsis}}</view>
						</view>
					</view>
				</view>
			</view>
			<u-empty v-if="list.length == 0" mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" width="150px"
				height="150px" text="列表为空" textSize="18">
			</u-empty>
			<view style="padding-bottom: 100rpx;">
				<u-loadmore v-if="loading" status="loading" />
				<u-loadmore v-if="isLastPage" status="nomore" />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				limit: 10,
				list: [],
				isLastPage: false,
				loading: false,
				adImage:[], // 广告图片
				rowBar:[], // 公告
				rowBarList:[]
			}
		},
		onLoad() {
			this.handNoticeBar()
			this.getadImage()
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getFindList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getFindList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getFindList();
			} else {
				this.isLastPage = true
			}
		},
		methods: {
			// 跳转到公告详情
			handleRowBarInfo(e){
				console.log(e)
				uni.navigateTo({
					url:'/pages/tab/find/adBar?id=' + this.rowBarList[e].id
				})
			},
			// 获取公告列表
			async handNoticeBar(){
				let res = await this.$api.post(global.apiUrls.postAdfindList, {
					typeid: 21
				}, {
					token: true
				})
				console.log(res)
				let arr = []
				arr = res.data.data.data.map(item=>{
					return item.title
				})
				console.log(arr)
				this.rowBar = arr
				this.rowBarList = res.data.data.data
			},
			// 跳转到发现详情
			handleJump(item){
				uni.navigateTo({
					url:'/pages/tab/find/find-info?id=' + item.id
				})
			},
			// 获取广告
			async getadImage(){
				let res = await this.$api.post(global.apiUrls.postAdfind, {
					typeid: 21
				}, {
					token: true
				})
				console.log( res.data.data)
				let arr = []
				arr = res.data.data.map(item=>{
					return item.thumb
				})
				this.adImage = arr
			},
			// 列表
			async getFindList() {
				let res = await this.$api.post(global.apiUrls.postShoolList, {
					page: this.page,
					limit: this.limit,
					category_id: 28
				}, {
					token: true
				})
				let arr = []
				let image = ''
				arr = res.data.data.data.map(item=>{
					if(item.img_url.length>0){
						image = item.img_url[0]
					}else{
						image = ''
					}
					return {
						id:item.id,
						image:image,
						title:item.title,
						synopsis:item.synopsis,
						update_time:item.update_time
					}
				})
				this.list = [...this.list, ...arr]
			}
		}
	}
</script>

<style scoped>
	.list-item-desc {
		font-weight: 500;
		font-size: 24rpx;
		color: #808080;
		width: 300rpx;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.list-icon {
		width: 26rpx;
		height: 26rpx;
		flex-shrink: 0;
		margin-right: 10rpx;
	}

	.list-item-bottom {
		display: flex;
		align-items: center;
	}

	.list-item-image {
		width: 335rpx;
		height: 335rpx;
		flex-shrink: 0;
		/* margin-bottom: 20rpx; */
	}

	.list-item-title {
		font-weight: 500;
		font-size: 28rpx;
		color: #333333;
		margin-bottom: 20rpx;
	}

	.list-item:nth-child(2n) {
		margin-right: 0;
	}

	.list-item {
		width: 335rpx;
		background-color: #ffffff;
		border-radius: 20rpx;
		overflow: hidden;
		margin-right: 20rpx;
	}

	.list-view {
		display: flex;
		flex-wrap: wrap;
	}

	.image-ad {
		width: 100%;
		height: 360rpx;
		flex-shrink: 0;
		margin-bottom: 30rpx;
	}

	.header-view {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 20rpx;
		font-size: 16px;
		color: #333333;
		margin: 90rpx 0 30rpx 0;
	}

	.pages-view {
		width: 100%;
		min-height: 100vh;
		overflow: hidden;
		background: url('https://localelife.chunchuangkeji.cn/static/home_bg.jpg') no-repeat;
		background-size:100% 100%;
	}
</style>